import cv2
import os
from glob import glob

# 提取轮廓
def edge(filename):
    img = cv2.imread(filename, cv2.IMREAD_GRAYSCALE)

    img_edge = cv2.adaptiveThreshold(img, 255,
                                     cv2.ADAPTIVE_THRESH_MEAN_C,
                                     cv2.THRESH_BINARY,
                                     blockSize=5,
                                     C=7)
    
    # 反相
    img_edge = cv2.bitwise_not(img_edge)
    
    save_filename = '%s.png' % (os.path.basename(filename).split('.')[0])
    cv2.imwrite('images/lineFrames/' + save_filename, img_edge)


if __name__ == "__main__":
    # if not os.path.exists('edges'):
    #     os.makedirs('edges')
    file_list = glob('images/frames/*.png')
    for filename in file_list:
        edge(filename)